package studio.banner.reference.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import studio.banner.reference.entity.UserInfo;
import studio.banner.reference.service.UserInfoService;
import studio.banner.reference.util.ResultBean;
@RequestMapping("/admin")
@Controller
public class AdminController {
	@Autowired
	private UserInfoService userInfoService;
	/*
	 * 查询所有的。
	 */
	@RequestMapping("/alllist")
	public String alllist(HttpServletRequest request) {
		List<UserInfo> infos=userInfoService.allList();
		request.setAttribute("infos", infos);
		return "/admin/admin";
	}
	/*
	 * 删除单个用户信息
	 */
	@RequestMapping("deleteone")
	public  ResultBean<Integer> deleteone(@RequestParam("id") String id) {
		Integer ids=Integer.parseInt(id);
		return new ResultBean<>(userInfoService.deleteone(ids));
	}
	/*
	 * 删除多个用户信息 
	 */
	@RequestMapping("/deletelist")
	public  ResultBean<Integer> deletelist(@RequestParam("ids") List<Integer> ids ) {
		userInfoService.deletelist(ids);
		return new ResultBean<>(userInfoService.deletelist(ids));
	}
	/*
	 * 更新用户信息
	 */
	@RequestMapping("/update")
	public  ResultBean<Integer> update(@ModelAttribute("u") UserInfo user) {
		userInfoService.update(user);
		return new ResultBean<>(userInfoService.update(user));
	}
	/*
	 * 模糊查询name和studentid
	 */
	@RequestMapping("/selectstudentidandname")
	public ResultBean<List<UserInfo>> selectstudentidandname(@RequestBody UserInfo user) {
		List<UserInfo> infos=userInfoService.selectstudentidandname(user);
		return new ResultBean<>(infos);
	}
	
}
